package com.mephi.oshs.view.impl;

import com.mephi.oshs.Main;
import com.mephi.oshs.presenter.PresenterManager;
import com.mephi.oshs.view.api.IView;
import com.mephi.oshs.view.api.IViewManager;
import com.mephi.oshs.view.lang.Languages;
import com.mephi.oshs.view.lang.TextManager;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

public abstract class AbstractView extends ViewPart implements IView {
    private static final IViewManager VIEW_MANAGER = Main.VIEW_MANAGER;

    protected static final Languages LANGUAGE = Languages.RUS;
    protected static final TextManager TEXT_MANAGER = TextManager.getInstance(LANGUAGE);

    protected Composite parent;

    /**
     * This is a callback that will allow us to create the viewer and initialize it.
     */
    @Override
    public void createPartControl(Composite parent) {
        this.parent = parent;
        createGUI();
        register();
        bind();
    }

    @Override
    public void setFocus() {
        this.parent.setFocus();
    }

    protected void register() {
        VIEW_MANAGER.registerView(this);
    }

    protected void bind() {
        PresenterManager.getInstance(VIEW_MANAGER).bindView(this);
    }

    public abstract void createGUI();
}
